Vue.component('item', {
    template: '#item-template',
    props: {
      model: Object
    },
    data: function () {
      return {
        open: false
      }
    },
    computed: {
      isFolder: function () {
        return this.model.children &&
          this.model.children.length
      }
    },
    methods: {
      toggle: function () {
        if (this.isFolder) {
            this.open = !this.open
            console.log(this.model.value)
         
        }else
        {
           let file=this.model.name;
           
           document.querySelector("#btnaId").innerText=file
           document.querySelector("#btnaId").href=M.ossBaseUrl+file;
           document.querySelector("#btnId").innerText=file
           this.color="green"
           fetch("/getFile?file="+file, {
                method: 'GET',
                mode: 'cors'
            }
            ).then((res) => {
                return res.text()
            }).then((res) =>{
              mingload(getlanguage(file),res)
              console.log(res)
            }).catch((error) => {
                console.error(error)
            });
        }
      },
      changeType: function () {
        if (!this.isFolder) {
          Vue.set(this.model, 'children', [])
          this.addChild()
          this.open = true
        }
      },
      addChild: function () {
        // this.model.children.push({
        //   name: 'new stuff'
        // })
      },
      openFolder:function(){
  
      }
    }
  })
  

  M.require("/tree").then(async d=>{
    let r= await M.request.get("getOssBaseUrl")
    M.ossBaseUrl= r.data
    window.demo = new Vue({
      el: '#demo',
      data: {
        treeData: d
      }
    })
  })

  // boot up the demo
